﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wise.Entities;

namespace Wise.Entities
{
    public static class DataTableExtersion
    {
        public static List<Dictionary<string,string>> ToList(this DataTable dt
            ,Func<DataRow, string,string> getter)
        {
            List<Dictionary<string, string>> rs = new List<Dictionary<string, string>>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Dictionary<string, string> dic = new Dictionary<string, string>();
                   DataRow row = dt.Rows[i];
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    DataColumn dc = dt.Columns[j];
                    dic.Add(dc.ColumnName, getter(row, dc.ColumnName));
                }
                rs.Add(dic);
            }
            return rs;
        }
    }
}
